import trees
import treePlotter as tp
import matplotlib.pyplot as plt

#记录下： python传值和传引用，其实都是在传对象，所以都是传引用,因此labels会被更改
#测试得到的Tree的数组
myDat,labels = trees.createDataSet()
print(labels)
myLabels = labels[:] #python复制列表需要这样切片的做法 ；
#myLabels = labels 这种做法就是指针引用，一修改都全都修改

myTree = trees.createTree(myDat,labels)#这个createTree会把labels改掉
print(myLabels)
print(labels)
print(myTree)

#绘制带箭头的注解	
def plotNodeMyTest(nodeTxt, centerPt, parentPt, nodeType):
    createPlotMyTest.ax1.annotate(nodeTxt, xy=parentPt,  xycoords='axes fraction',
             xytext=centerPt, textcoords='axes fraction',
             va="center", ha="center", bbox=nodeType, arrowprops=tp.arrow_args )

#测试使用的树的画法 
def createPlotMyTest():
	fig = plt.figure(1,facecolor = 'white')
	fig.clf()
	createPlotMyTest.ax1 = plt.subplot(111,frameon = False)
	plotNodeMyTest('a decision node',(0.5,0.1),(0.1,0.5),tp.decisionNode)
	plotNodeMyTest('a leaf node',(0.8,0.1),(0.3,0.8),tp.leafNode)
	plt.show()
	
#print(tp.getNumLeafs(myTree))#获取树的叶子个数
#print(tp.getTreeDepth(myTree))#获取树的深度
print(trees.classify(myTree,myLabels,[1,0]))#利用[1,0]来分类得出是否为鱼类
tp.createPlot(myTree)#创建决策树的图
	
#测试函数变量例子
#def funcA():
#	funcA.ax1 =1;
#
#funcA();
#print(funcA.ax1)



















